home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / drivers / nics / pktdrv7 / tail.asm < prev    next >
Encoding:
Assembly Source File  |  1990-08-29  |  10.2 KB  |  414 lines

  1. ;   PC/FTP Packet Driver source, conforming to version 1.05 of the spec
  2. ;   Russell Nelson, Clarkson University.  July 20, 1988
  3. ;   Updated to version 1.08 Feb. 17, 1989.
  4. ;   Copyright 1988,1989 Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     extrn    phd_dioa: byte
  25.     extrn    phd_environ: word
  26.     extrn    flagbyte: byte
  27.  
  28.     public    print_number
  29. print_number:
  30. ;enter with dx -> dollar terminated name of number, di ->dword.
  31. ;exit with the number printed and the cursor advanced to the next line.
  32.     mov    ah,9            ;print the name of the number.
  33.     int    21h
  34.     mov    al,'0'
  35.     call    chrout
  36.     mov    al,'x'
  37.     call    chrout
  38.     mov    ax,[di]            ;print the number in hex.
  39.     mov    dx,[di+2]
  40.     call    dwordout
  41.     mov    al,' '
  42.     call    chrout
  43.     mov    al,'('
  44.     call    chrout
  45.     mov    ax,[di]            ;print the number in decimal.
  46.     mov    dx,[di+2]
  47.     call    decout
  48.     mov    al,')'
  49.     call    chrout
  50.     mov    al,CR
  51.     call    chrout
  52.     mov    al,LF
  53.     call    chrout
  54.     ret
  55.  
  56.     include    decout.asm
  57.     include    digout.asm
  58.     include    chrout.asm
  59.  
  60. end_tail_1    label    byte        ; end of the delayed init driver
  61.  
  62. ;usage_msg is of the form "usage: driver [-d -n] <packet_int_no> <args>"
  63.     extrn    usage_msg: byte
  64.  
  65. ;copyright_msg is of the form:
  66. ;"Packet driver for the foobar",CR,LF
  67. ;"Portions Copyright 19xx, J. Random Hacker".
  68.     extrn    copyright_msg: byte
  69.  
  70. copyleft_msg    label    byte
  71.  db "Packet driver skeleton copyright 1988-90, Russell Nelson.",CR,LF
  72.  db "This program is free software; see the file COPYING for details.",CR,LF
  73.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  74.  db CR,LF
  75. crlf_msg    db    CR,LF,'$'
  76.  
  77. no_resident_msg    label    byte
  78.  db CR,LF,"*** Packet driver failed to initialize the board ***",CR,LF,'$'
  79.  
  80. ;parse_args should parse the arguments.
  81. ;called with ds:si -> immediately after the packet_int_no.
  82.     extrn    parse_args: near
  83.  
  84. ;print_parameters should print the arguments.
  85.     extrn    print_parameters: near
  86.  
  87.     extrn    our_isr: near, their_isr: dword
  88.     extrn    packet_int_no: byte
  89.     extrn    is_at: byte, sys_features: byte
  90.     extrn    int_no: byte
  91.     extrn    driver_class: byte
  92.  
  93. location_msg    db    "Packet driver loaded at segment ",'$'
  94.  
  95. packet_int_no_name    db    "Packet interrupt number ",'$'
  96. eaddr_msg    db    "My Ethernet address is ",'$'
  97. aaddr_msg    db    "My ARCnet address is ",'$'
  98.  
  99. signature    db    'PKT DRVR',0
  100. signature_len    equ    $-signature
  101.  
  102. already_msg    db    CR,LF,"There is already a packet driver at ",'$'
  103. packet_int_msg    db    CR,LF
  104.         db    "Error: <packet_int_no> should be in the range 0x60 to 0x80"
  105.         db    '$'
  106. int_msg        db    CR,LF
  107.         db    "Error: <int_no> should be no larger than "
  108. int_msg_num    label    word
  109.         db    "xx"
  110.         db    '$'
  111.  
  112. our_address    db    EADDR_LEN dup(?)
  113.     public    etopen_diagn
  114. etopen_diagn    db    0        ; errorlevel from etopen if set
  115.  
  116. ;etopen should initialize the device.  If it needs to give an error, it
  117. ;can issue the error message and quit to dos.
  118.     extrn    etopen: near
  119.  
  120. ;get the address of the interface.
  121. ;enter with es:di -> place to get the address, cx = size of address buffer.
  122. ;exit with nc, cx = actual size of address, or cy if buffer not big enough.
  123.     extrn    get_address: near
  124.  
  125. already_error:
  126.     mov    dx,offset already_msg
  127.     mov    di,offset packet_int_no
  128.     call    print_number
  129.     mov    ax,4c05h        ; give errorlevel 5
  130.     int    21h
  131.  
  132. usage_error:
  133.     mov    dx,offset usage_msg
  134.     public    error
  135. error:
  136.     mov    ah,9
  137.     int    21h
  138.     mov    ax,4c0ah        ; give errorlevel 10
  139.     int    21h
  140.  
  141.     public    start_1
  142. start_1:
  143.     mov    dx,offset copyright_msg
  144.     mov    ah,9
  145.     int    21h
  146.  
  147.     mov    dx,offset copyleft_msg
  148.     mov    ah,9
  149.     int    21h
  150.  
  151.     mov    si,offset phd_dioa+1
  152.     call    skip_blanks        ;end of line?
  153.     cmp    al,CR
  154.     je    usage_error
  155.  
  156. ;print the location we were loaded at.
  157.     mov    dx,offset location_msg
  158.     mov    ah,9
  159.     int    21h
  160.  
  161.     mov    ax,cs            ;print cs as a word.
  162.     call    wordout
  163.  
  164.     mov    dx,offset crlf_msg
  165.     mov    ah,9
  166.     int    21h
  167.  
  168. chk_options:
  169.     call    skip_blanks
  170.     cmp    al,'-'            ; any options?
  171.     jne    no_more_opt
  172.     inc    si            ; skip past option char
  173.     lodsb                ; read next char
  174.     or    al,20h            ; convert to lower case
  175.     cmp    al,'d'
  176.     jne    not_d_opt
  177.     or    flagbyte,D_OPTION
  178.     jmp    chk_options
  179. not_d_opt:
  180.     cmp    al,'n'
  181.     jne    not_n_opt
  182.     or    flagbyte,N_OPTION
  183.     jmp    chk_options
  184. not_n_opt:
  185.     cmp    al,'w'
  186.     jne    not_w_opt
  187.     or    flagbyte,W_OPTION
  188.     jmp    chk_options
  189. not_w_opt:
  190.     jmp    usage_error
  191. no_more_opt:
  192.  
  193.     mov    di,offset packet_int_no    ;parse the packet interrupt number
  194.     mov    bx,offset packet_int_no_name
  195.     call    get_number        ;  for them.
  196.  
  197.     call    parse_args
  198.     jc    usage_error
  199.  
  200.     call    skip_blanks        ;end of line?
  201.     cmp    al,CR
  202.     jne    usage_error
  203.  
  204.     mov    dx,offset packet_int_msg;make sure that the packet interrupt
  205.     cmp    packet_int_no,60h    ;  number is in range.
  206.     jae    packet_int_ok
  207.     cmp    packet_int_no,80h
  208.     jbe    packet_int_ok
  209.     jmp    error
  210. packet_int_ok:
  211.  
  212.     mov    ah,35h            ;get their packet interrupt.
  213.     mov    al,packet_int_no
  214.     int    21h
  215.  
  216.     lea    di,3[bx]        ;see if there is already a signature
  217.     mov    si,offset signature    ;  there.
  218.     mov    cx,signature_len
  219.     repe    cmpsb
  220.     jne    not_one_yet
  221.     jmp    already_error        ;yes, so we can't go there.
  222. not_one_yet:
  223.  
  224. ;
  225. ; Get the feature byte (if reliable) so we can know if it is a microchannel
  226. ; computer and how many interrupts there are
  227.     mov    ah,0c0h
  228.     int    15h            ; es:bx <- sys features block
  229.     mov    al,7            ;maximum interrupt on a PC
  230.     mov    int_msg_num,'7'+' '*256
  231.     jc    look_in_ROM
  232.     or    ah,ah
  233.     jnz    look_in_ROM
  234.     mov    dx,es:[bx]        ; # of feature bytes
  235.     cmp    dx,4
  236.     jae    got_features
  237. look_in_ROM:
  238.     mov    dx,0f000h        ;ROM segment
  239.     mov    es,dx
  240.     cmp    byte ptr es:[0fffeh],0fch;is this an AT?
  241.     jne    not_at            ;no.
  242.     or    sys_features,TWO_8259    ; ATs have 2nd 8259
  243.     jmp    isa_at            ; assume no microchannel
  244. got_features:
  245.     mov    ah,es:[bx+2]        ; model byte
  246.     cmp    ah,0fch
  247.     je    at_ps2
  248.     ja    not_at            ; FD, FE and FF are not ATs
  249.     cmp    ah,0f8h
  250.     je    at_ps2
  251.     ja    not_at            ; F9, FA and FB are not ATs
  252.     cmp    ah,09ah
  253.     jbe    not_at            ; old non-AT Compacs go here
  254. at_ps2:                    ; 9B - F8 and FC are assumed to
  255.     mov    ah,es:[bx+5]        ;   have reliable feature byte
  256.     mov    sys_features,ah
  257.     test    sys_features,TWO_8259    ; 2nd 8259 ?
  258.     jz    not_at
  259. isa_at:
  260.     inc    is_at
  261.     mov    al,15            ;maximum interrupt on an AT
  262.     mov    int_msg_num,'1'+'5'*256
  263.     cmp    int_no,2        ;map IRQ 2 to IRQ 9.
  264.     jne    not_at
  265.     mov    int_no,9
  266. not_at:
  267.  
  268.     mov    dx,offset int_msg    ;make sure that the packet interrupt
  269.     cmp    int_no,al        ;  number is in range.
  270.     jbe    int_ok
  271.     jmp    error
  272. int_ok:
  273.  
  274. ; If they chose the -d option, don't call etopen when we are loaded,
  275. ; but when we are called for the first time
  276. ;
  277. ; Save part of the tail, needed by delayed etopen
  278.     mov    dx,offset end_tail_1    ; save first part of tail
  279.     test    flagbyte,D_OPTION
  280.     jnz    delayed_open
  281.     call    etopen            ;init the driver.  If any errors,
  282.                     ;this routine returns cy.
  283.     jnc    yes_resident
  284.     jmp    no_resident
  285. delayed_open:
  286.     push    dx            ;remember where they want to end.
  287.     call    take_packet_int
  288.     jmp    delayed_open_1
  289.  
  290. yes_resident:
  291.     push    dx            ;remember where they want to end.
  292.  
  293.     call    print_parameters    ;echo our parameters.
  294.     or    flagbyte,CALLED_ETOPEN
  295.  
  296.     call    take_packet_int
  297.  
  298.     cmp    driver_class,1        ;Ethernet?
  299.     jne    print_addr_2        ;no, don't print what we don't have.
  300.  
  301.     push    ds
  302.     pop    es
  303.     mov    di,offset our_address
  304.     mov    cx,EADDR_LEN
  305.     call    get_address
  306.  
  307.     mov    dx,offset eaddr_msg
  308.     mov    ah,9
  309.     int    21h
  310.  
  311.     mov    si,offset our_address
  312.     call    print_ether_addr
  313.  
  314.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  315.     mov    ah,9
  316.     int    21h
  317.  
  318. print_addr_2:
  319.  
  320.     cmp    driver_class,8        ;ARCnet?
  321.     jne    print_addr_3        ;no, don't print what we don't have.
  322.  
  323.     push    ds
  324.     pop    es
  325.     mov    di,offset our_address
  326.     mov    cx,ARCADDR_LEN
  327.     call    get_address
  328.  
  329.     mov    dx,offset aaddr_msg
  330.     mov    ah,9
  331.     int    21h
  332.  
  333.     mov    al,our_address
  334.     mov    cl,' '            ;Don't eliminate leading zeroes.
  335.     call    byteout
  336.  
  337.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  338.     mov    ah,9
  339.     int    21h
  340.  
  341. print_addr_3:
  342. delayed_open_1:
  343.  
  344.     mov    ah,49h            ;free our environment, because
  345.     mov    es,phd_environ        ;  we won't need it.
  346.     int    21h
  347.  
  348.     mov    bx,1            ;get the stdout handle.
  349.     mov    ah,3eh            ;close it in case they redirected it.
  350.     int    21h
  351.  
  352.     pop    dx            ;get their ending address.
  353.     add    dx,0fh            ;round up to next highest paragraph.
  354.     mov    cl,4
  355.     shr    dx,cl
  356.     mov    ah,31h            ;terminate, stay resident.
  357.     mov    al,etopen_diagn        ; errorlevel (0 - 9, just diagnostics)
  358.     int    21h
  359.  
  360. no_resident:
  361.     mov    dx,offset no_resident_msg
  362.     mov    ah,9
  363.     int    21h
  364.  
  365.     mov    ax,4c00h + 32        ; give errorlevel 32
  366.     cmp    al,etopen_diagn
  367.     ja    no_et_diagn        ; etopen gave specific reason?
  368.     mov    al,etopen_diagn        ; yes, use that for error level
  369. no_et_diagn:
  370.     int    21h
  371.  
  372. ;             Suggested errorlevels:
  373. ;
  374. ; _____________________  0 = normal
  375. ;              1 = unsuitable memory address given; corrected
  376. ; In most cases every-     2 = unsuitable IRQ level given; corrected
  377. ; thing should work as     3 = unsuitable DMA channel given; corrected
  378. ; expected for lev 1-5     4 = unsuitable IO addr given; corrected (only 1 card)
  379. ; _____________________     5 = packet driver for this int # already loaded
  380. ; External errors, when    20 = general cable failure (but pkt driver is loaded)
  381. ; corrected normal    21 = network cable is open             -"-
  382. ; operation starts    22 = network cable is shorted          -"-
  383. ; _____________________ 23 = 
  384. ; Packet driver not    30 = usage message
  385. ; loaded. A new load    31 = arguments out of range
  386. ; attempt must be done    32 = unspecified device initialization error
  387. ;            33 = 
  388. ;            34 = suggested memory already occupied
  389. ;            35 = suggested IRQ already occupied
  390. ;            36 = suggested DMA channel already occupied
  391. ;            37 = could not find the network card at this IO address
  392.  
  393.  
  394. take_packet_int:
  395.     mov    ah,35h            ;remember their packet interrupt.
  396.     mov    al,packet_int_no
  397.     int    21h
  398.     mov    their_isr.offs,bx
  399.     mov    their_isr.segm,es
  400.  
  401.     mov    ah,25h            ;install our packet interrupt
  402.     mov    dx,offset our_isr
  403.     int    21h
  404.     ret
  405.  
  406.     include    getnum.asm
  407.     include    getdig.asm
  408.     include    skipblk.asm
  409.     include    printea.asm
  410.  
  411. code    ends
  412.  
  413.     end
  414.